#include "PAP_defs.h"
#include "derivative.h"

#define SCI_4800BAUD 104
#define SCI_9600BAUD 52
#define SCI_19200BAUD 26
#define SCI_38400BAUD 13

/* SCI CONFIGURATION PART 1: define the features that are needed */
    
    //#define LOOP_MODE_SELECT
    //#define SCI_WAIT_INACTIVE
    //#define SINGLE_WIRE_SCI
    //#define MODE_9BIT
    //#define ADDRESS_MARK_WAKEUP
    //#define IDLE_LINE_STOP_BIT
    //#define PARITY_ENABLE
    //#define PARITY_ODD

/* SCI CONFIGURATION PART 1 ends here*/

/* SCI CONFIGURATION PART 2: define the features that are needed */
    
    //#define TX_INT_ENABLED
    //#define TX_COMP_INT_ENABLED
    #define RX_INT_ENABLED
    //#define IDLE_LINE_INT_ENABLED
    #define TX_ENABLED
    #define RX_ENABLED
    //#define RX_STANDBY
    //#define SEND_BREAK

/* SCI CONFIGURATION PART 2 ends here*/

/* DO NOT MODIFY */
#ifdef LOOP_MODE_SELECT
    #define LOOP 0x80
#else
    #define LOOP 0x00
#endif

#ifdef SCI_WAIT_INACTIVE
    #define SCI_WAIT 0x40
#else 
    #define SCI_WAIT 0x00
#endif 

#ifdef SINGLE_WIRE_SCI
    #define SCI_DUPLEX 0x20
#else
    #define SCI_DUPLEX 0x00
#endif

#ifdef MODE_9BIT
    #define BIT_MODE 0x10
#else
    #define BIT_MODE 0x00
#endif

#ifdef ADDRESS_MARK_WAKEUP
    #define WAKEUP 0x80
#else
    #define WAKEUP 0x00
#endif

#ifdef IDLE_LINE_STOP_BIT
    #define IDLE_LINE_TYPE 0x40
#else
    #define IDLE_LINE_TYPE 0x00
#endif

#ifdef PARITY_ENABLE
    #define PARITY 0x20
#else
    #define PARITY 0x00
#endif

#ifdef PARITY_ODD
    #define PARITY_TYPE 0x01
#else
    #define PARITY_TYPE 0x00
#endif

#define SCI_CONTROL_REG1    (LOOP | SCI_WAIT | SCI_DUPLEX | BIT_MODE | WAKEUP |  \
                            IDLE_LINE_TYPE | PARITY | PARITY_TYPE ) 

#ifdef TX_INT_ENABLED
    #define TX_INT 0x80
#else
    #define TX_INT 0x00
#endif

#ifdef TX_COMP_INT_ENABLED
    #define TX_COMP_INT 0x40
#else 
    #define TX_COMP_INT 0x00
#endif 

#ifdef RX_INT_ENABLED
    #define RX_INT 0x20
#else
    #define RX_INT 0x00
#endif

#ifdef IDLE_LINE_INT_ENABLED
    #define IDLE_LINE_INT 0x10
#else
    #define IDLE_LINE_INT 0x00
#endif

#ifdef TX_ENABLED
    #define TX_EN 0x08
#else
    #define TX_EN 0x00
#endif

#ifdef RX_ENABLED
    #define RX_EN 0x04
#else
    #define RX_EN 0x00
#endif

#ifdef RX_STANDBY
    #define RX_WAITING 0x02
#else
    #define RX_WAITING 0x00
#endif

#ifdef SEND_BREAK
    #define BREAK_QUEUE 0x01
#else
    #define BREAK_QUEUE 0x00
#endif

#define SCI_CONTROL_REG2    (TX_INT | TX_COMP_INT | RX_INT | IDLE_LINE_INT |  \
                            TX_EN | RX_EN | RX_WAITING | BREAK_QUEUE)
#define SCI_CONTROL_REG3 0

/* DO NOT MODIFY ENDS HERE */

void vfnSCI_SetBaudRate (uint16 u16baudrate);

void vfnSCI_Init (void);

void vfnSCI_SendByte (uint8 u8data);

uint8 u8SCI_TxBufferEmpty (void);

uint8 u8SCI_TxComplete (void);

uint8 u8SCI_RxRegisterFull (void);

uint8 u8SCI_CheckOverrun (void);

uint8 u8SCI_ReadByte (void);

uint8 u8SCI_RxPending (void);



